/**
 * 
 */
package ModelLayer.FileHandlers;

import java.util.ArrayList;

import ModelLayer.Customer;

/**
 * This class is an abstraction on top of BaseFileHandler, access and changes to customers
 * should only occour through the public methods of this class.
 * @author Frank Eskelund
 * @version 
 */
public class CustomerFileHandler extends BaseFileHandler {

	public CustomerFileHandler(String fileName)
	{
		super(fileName);
	}
	
	public void add(Customer Customer)
	{
		ArrayList<Customer> Customers = getAll();
		Customers.add(Customer);
		super.saveToFile(Customers);
	}
	
	/**
	 * This method is used to update the stored Customers. All the Customers will be replaced with
	 * the ones in the passed ArrayList
	 * @param Customers
	 * The list of Customers to replace the existing ones.
	 */
	public void update(ArrayList<Customer> Customers)
	{
		super.saveToFile(Customers);
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<Customer> getAll()
	{
		if(!fileExists()){
			return new ArrayList<Customer>();
		}
		
		return (ArrayList<Customer>)readFromFile();
	}
	
}

